package com.cloud.adrian.novel.user.manager.redis;

import com.cloud.adrian.novel.common.constant.CacheConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Objects;

/**
 * 验证码管理类
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/17
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class VerifyCodeManager {
    private final StringRedisTemplate redisTemplate;

    /**
     * 校验图形验证码
     */
    public boolean imgVerifyCodeOk(String sessionId, String verifyCode) {
        return Objects.equals(redisTemplate.opsForValue()
                .get(CacheConstants.IMAGE_VERIFY_CODE_CACHE_KEY + sessionId) , verifyCode);
    }

    /**
     * 从redis删除验证码
     */
    public void removeImgVerifyCode(String sessionId) {
        redisTemplate.delete(CacheConstants.IMAGE_VERIFY_CODE_CACHE_KEY + sessionId);
    }
}
